/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.validation.client;

import com.cleangwt.validation.client.constraints.relative.EqValidation;
import com.cleangwt.validation.client.constraints.relative.GeValidation;
import com.cleangwt.validation.client.constraints.relative.GtValidation;
import com.cleangwt.validation.client.constraints.relative.LeValidation;
import com.cleangwt.validation.client.constraints.relative.LtValidation;
import com.google.gwt.user.client.ui.HasValue;

/**
 * The {@link ValidationContextBuilder} for building {@link ValidationContext} with multiple input
 * field.
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 * @see Validator
 */
public class MultiFieldBuilder extends ValidationContextBuilder {

  /**
   * Creates a multi-field context builder with the given inputs.
   * 
   * @param inputs the inputs
   */
  public MultiFieldBuilder(HasValue<?>... inputs) {
    super(inputs);
    assert inputs != null && inputs.length > 1 : "The relative context must have two or more inputs.";
  }

  /**
   * Sets the binding groups for the next {@link Validation}s to add.
   * 
   * @param groups the groups
   * @return this for continuously building
   */
  public MultiFieldBuilder forGroups(String... groups) {
    return (MultiFieldBuilder) super.forGroups(groups);
  }

  /**
   * Adds a {@link Validation} to the {@link ValidationContext}.
   * 
   * @param validation the validation
   * @return this for continuously building
   */
  public MultiFieldBuilder add(Validation validation) {
    return (MultiFieldBuilder) super.add(validation);
  }

  /**
   * Adds a {@link EqValidation} to the {@link ValidationContext}.
   * 
   * @param field1 the name of input1 for composing errorMessage message
   * @param field2 the name of input2 for composing errorMessage message
   * @return this for continuous binding
   */
  public MultiFieldBuilder eq(String field1, String field2) {
    return add(new EqValidation(ValidationMessages.Impl.eq(field1, field2)));
  }

  /**
   * Adds a {@link GtValidation} to the {@link ValidationContext}.
   * 
   * @param field1 the name of input1 for composing errorMessage message
   * @param field2 the name of input2 for composing errorMessage message
   * @return this for continuous binding
   */
  public MultiFieldBuilder gt(String field1, String field2) {
    return add(new GtValidation(ValidationMessages.Impl.ge(field1, field2)));
  }

  /**
   * Adds a {@link GeValidation} to the {@link ValidationContext}.
   * 
   * @param field1 the name of input1 for composing errorMessage message
   * @param field2 the name of input2 for composing errorMessage message
   * @return this for continuous binding
   */
  public MultiFieldBuilder ge(String field1, String field2) {
    return add(new GeValidation(ValidationMessages.Impl.ge(field1, field2)));
  }

  /**
   * Adds a {@link LtValidation} to the {@link ValidationContext}.
   * 
   * @param field1 the name of input1 for composing errorMessage message
   * @param field2 the name of input2 for composing errorMessage message
   * @return this for continuous binding
   */
  public MultiFieldBuilder lt(String field1, String field2) {
    return add(new LtValidation(ValidationMessages.Impl.lt(field1, field2)));
  }

  /**
   * Adds a {@link LeValidation} to the {@link ValidationContext}.
   * 
   * @param field1 the name of input1 for composing errorMessage message
   * @param field2 the name of input2 for composing errorMessage message
   * @return this for continuous binding
   */
  public MultiFieldBuilder le(String field1, String field2) {
    return add(new LeValidation(ValidationMessages.Impl.le(field1, field2)));
  }
}
